﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

/// <summary>
/// 技能数据
/// </summary>
public class SkillData
{
    private int index = 0;//技能索引
    public string m_skillID;//技能数据加载
    /// <summary>
    /// 上次执行时间
    /// </summary>
    private float lastExecuteTime = -1;
    /// <summary>
    /// 技能详情
    /// </summary>
    private SkillDataGenerate m_skillInfo;
    /// <summary>
    /// 之前技能状态数据
    /// </summary>
    private SkillStatusDataGenerate m_beforeInfo;
    /// <summary>
    /// 当前技能状态数据
    /// </summary>
    private SkillStatusDataGenerate m_currentInfo;
    /// <summary>
    /// 之后技能状态数据
    /// </summary>
    private SkillStatusDataGenerate m_laterInfo;

    public SkillDataGenerate SkillInfo
    {
        get {
            if (m_skillInfo==null)
            {
                SkillInfo = DataGenerateManager<SkillDataGenerate>.GetData(m_skillID);
            }

            return m_skillInfo;
        }
        set { m_skillInfo = value; }
    }

    public SkillStatusDataGenerate BeforeInfo
    {
        get
        {
            if (m_beforeInfo == null)
            {
                m_beforeInfo = DataGenerateManager<SkillStatusDataGenerate>.GetData(SkillInfo.m_BeforeStatus);
            }

            return m_beforeInfo;
        }
        set { m_beforeInfo = value; }
    }
    public SkillStatusDataGenerate CurrentInfo
    {
        get
        {
            if (m_currentInfo == null)
            {
                m_currentInfo = DataGenerateManager<SkillStatusDataGenerate>.GetData(SkillInfo.m_BeforeStatus);
            }

            return m_beforeInfo;
        }
        set { m_currentInfo = value; }
    }
    public SkillStatusDataGenerate LaterInfo
    {
        get
        {
            if (m_laterInfo == null)
            {
                m_laterInfo = DataGenerateManager<SkillStatusDataGenerate>.GetData(SkillInfo.m_BeforeStatus);
            }

            return m_beforeInfo;
        }
        set { m_laterInfo = value; }
    }
    /// <summary>
    /// 前段状态持续时间
    /// </summary>
    public float BeforeTime
    {
        get { return BeforeInfo.m_Time; }
    }
    /// <summary>
    /// 前段状态最大持续时间
    /// </summary>
    public float HitTime
    {
        get { return BeforeTime + SkillInfo.m_HitTime; }
    }
    /// <summary>
    /// 前段+中段持续时长
    /// </summary>
    public float CurrentTime
    {
        get { return BeforeTime + CurrentInfo.m_Time; }
    }
    /// <summary>
    ///前段+中段+后段持续时长
    /// </summary>
    public float LaterTime
    {
        get { return CurrentTime + LaterInfo.m_Time; }
        
    }
    /// <summary>
    /// 技能冷却时长
    /// </summary>
    public float CDSpace
    {
        get { return SkillInfo.m_CD; }
    }
    /// <summary>
    /// 技能索引
    /// </summary>
    public int Index
    {
        get { return index; }
        set { index = value; }
    }
    /// <summary>
    /// 上次执行时间
    /// </summary>
    public float LastExecuteTime
    {
        get
        {
            return lastExecuteTime;
        }

        set
        {
            lastExecuteTime = value;
        }
    }
    public SkillData()
    {
    }
    public SkillData(string skillID, int index = 0)
    {
        m_skillID = skillID;
        Index = index;
        UpdateInfo();
        Reset();
    }

    #region 外部调用
    public SkillDataGenerate GetInfo()
    {
        return SkillInfo;
    }
    /// <summary>
    /// 开始cd
    /// </summary>
    /// <param name="lastExecuteTime"></param>
    public void BegionCD(float lastExecuteTime)
    {
        LastExecuteTime = lastExecuteTime + 0.4f;
    }
    /// <summary>
    /// 重置运行时数据
    /// </summary>
    public void Reset()
    {
        LastExecuteTime = -1;
    }
    #endregion
    public void UpdateInfo()
    {
        if (m_skillID != "" && m_skillID != "null")
        {
            SkillInfo = DataGenerateManager<SkillDataGenerate>.GetData(m_skillID);
            BeforeInfo = DataGenerateManager<SkillStatusDataGenerate>.GetData(SkillInfo.m_BeforeStatus);
            CurrentInfo = DataGenerateManager<SkillStatusDataGenerate>.GetData(SkillInfo.m_CurrentStatus);
            LaterInfo = DataGenerateManager<SkillStatusDataGenerate>.GetData(SkillInfo.m_LaterStatus);
        }
    }
    /// <summary>
    /// 深复制
    /// </summary>
    /// <returns></returns>
    public SkillData DeepCopy()
    {
        SkillData sd = new SkillData(m_skillID, Index);

        return sd;
    }
}

